﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Mapa.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="headContent" ContentPlaceHolderID="HeadContentPlaceHolder" runat="server">
    <link type="text/css" href="<%= ResolveUrl("~") %>css/le-frog/jquery-ui-1.8.1.custom.css"
        rel="Stylesheet" />
    <script type="text/javascript" src="<%= ResolveUrl("~") %>Scripts/jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~") %>Scripts/jquery-ui-1.8.1.custom.min.js"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~") %>Scripts/jquery.ui.datepicker-es.js"></script>
    <link href="<%= ResolveUrl("~") %>Content/timepicker.css" rel="stylesheet" type="text/css" />
    <script src="<%= ResolveUrl("~") %>Scripts/jquery.mousewheel.js" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~") %>Scripts/jquery.timepicker.js" type="text/javascript"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~") %>Content/Mapa/dragzoom.js" ></script>
    <script type="text/javascript" src="<%= ResolveUrl("~") %>Content/Mapa/labeledmarker.js" ></script>

    <script type="text/javascript" language="javascript">
        $(function () {
            <%if ((bool)ViewData["IsAdmin"])
              { %>
                $("#Clientes").change(function () {
                    document.location.href = "<%= ResolveUrl("~") %>Mapa/BusquedaAvanzada/?clienteId=" + $(this).val();                
                });
            <%} %>

            $("#comboUnidades").change(function () {
                document.location.href = "<%= ResolveUrl("~") %>Mapa/BusquedaAvanzada/?clienteId=" + $("#Clientes").val() + "&und=" + $("#comboUnidades").val();
            });
        });
    </script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#tp").timepicker({ divId: "mytimepicker" });
            $("#tp2").timepicker({ divId: "mytimepicker" });
            $("#tp3").timepicker();
            $("#tp4").timepicker();
        });
    </script>
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAA3h-vyP_6IePyY5uOJxHE7xQLyozoXpHWq4B17xiQz7RwuyV7WBQE9Z-5SVWXfnZJ4BsxpiPPG_oifg"
        type="text/javascript">
    </script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#fechaDesde").datepicker();
        })
    </script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#fechaHasta").datepicker();
        })
    </script>
    <!-- metodo nuevo de consulta-->
    <script type="text/javascript">
        function GetDatos() {


            var id = $("#comboUnidades").val();
            var fecha_desde = $("#fechaDesde").val();
            var fecha_hasta = $("#fechaHasta").val();
            var hora_desde = $("#tp").val();

            var hora_hasta = $("#tp2").val();

            //alert(hora_desde);
            //alert(hora_hasta);


            fecha_desde = fecha_desde + " " + hora_desde
            fecha_hasta = fecha_hasta + " " + hora_hasta

            //alert(fecha_desde);

            //window.location = '../Mapa/Reportes?id=' + $("#comboUnidades").val() + '&fecha_desde=' + $("#fechaDesde").val() + '&fecha_hasta=' + $("#fechaHasta").val()


            window.location.href = "<%= ResolveUrl("~") %>Mapa/Reportes?id=" + id + "&fecha_desde='" + fecha_desde + "'&fecha_hasta='" + fecha_hasta + "'"

        }
    </script>
    <script type="text/javascript">

        //$(function () { $("#navbar").hide(); });

        function initialize() {

            if (GBrowserIsCompatible()) {
                var map = new GMap2(document.getElementById("map_canvas"));
                //map.setMapType(G_HYBRID_MAP);
                //map.setMapType(G_SATELLITE_3D_MAP);
                map.addControl(new DragZoomControl());
                var baseIcon = new GIcon();
                baseIcon.iconSize = new GSize(32, 32);
                baseIcon.shadowSize = new GSize(56, 32);
                baseIcon.iconAnchor = new GPoint(16, 32);
                baseIcon.infoWindowAnchor = new GPoint(16, 0);
                var edificio = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal3/icon21.png", null, "http://maps.google.com/mapfiles/kml/pal3/icon21s.png");
                var center = new GLatLng(-0.206212, -78.481501);
                map.setCenter(center, 18);
                //map.addControl(new GControl(new CarouselMapTypeControl())); 

                opts = {
                    "icon": edificio,
                    "clickable": true,
                    "title": "este el primero",
                    "labelText": "1",
                    "labelOffset": new GSize(-6, -10)
                };
                var marker = new LabeledMarker(center, opts);


                //var marker = new GMarker(center, edificio);

                map.setUIToDefault();
                map.enableRotation();
                var ovcontrol = new GOverviewMapControl(new GSize(200, 200));
                map.addControl(ovcontrol);
                
//                GEvent.addListener(marker, "click", function () {
//                    marker.openInfoWindowHtml("<b style='color: #0000FF'>Startel Systems</b><br/><i>Pasaje Génova N24-531 y Rubio de Arévalo</i><br/><i>Telf: (+593) 2232189</i><br/><a href='http://www.startelsystems.com.ec'>Visitanos en nuestra Web!</a> ");
//                });
//                marker.openInfoWindowHtml("<b style='color: #0000FF'>Startel Systems</b><br/><i>Pasaje Génova N24-531 y Rubio de Arévalo</i><br/><i>Telf: (+593) 2232189</i><br/><a href='http://www.startelsystems.com.ec'>Visitanos en nuestra Web!</a> ");
                //                map.addOverlay(marker);

//                GEvent.addListener(marker, "click", function () {
//                    marker.openInfoWindowHtml("I'm a Labeled Marker!");
//                });
                //marker.openInfoWindowHtml("<b style='color: #0000FF'>Startel Systems</b><br/><i>Pasaje Génova N24-531 y Rubio de Arévalo</i><br/><i>Telf: (+593) 2232189</i><br/><a href='http://www.startelsystems.com.ec'>Visitanos en nuestra Web!</a> ");
                




                map.addOverlay(marker);
                

            }
        }

        $(window).load(function () {
            initialize();
        });

        $(window).unload(function () {
            GUnload();
        });
    </script>
    <script type="text/javascript">
        function GetDatosMapa() {

           //alert("entre");
            var id = $("#comboUnidades").val();
            var fecha_desde = $("#fechaDesde").val();
            var fecha_hasta = $("#fechaHasta").val();
            var hora_desde = $("#tp").val();
            
            var hora_hasta = $("#tp2").val();

            //alert(hora_desde);
            //alert(hora_hasta);
            

            fecha_desde=fecha_desde+" "+hora_desde
            fecha_hasta=fecha_hasta+" "+hora_hasta

           // alert (fecha_desde);

           $.ajax({
                type: "POST",
                url: "<%= ResolveUrl("~") %>Mapa/ReportesMapa",
                data: "Id="+id+"&fecha_desde='"+fecha_desde+"'&fecha_hasta='"+fecha_hasta+"'",
                dataType: "json",
                cache: false,
                success: function (response) {
                    //entre suscces

                    if (GBrowserIsCompatible()) {
                        var map = new GMap2(document.getElementById("map_canvas"));
                        //map.setMapType(G_HYBRID_MAP);
                        map.addMapType(G_SATELLITE_3D_MAP);
                         map.addControl(new DragZoomControl());
                        var baseIcon = new GIcon();
                        baseIcon.iconSize = new GSize(60, 60);
                        baseIcon.shadowSize = new GSize(56, 32);
                        baseIcon.iconAnchor = new GPoint(16, 32);
                        baseIcon.infoWindowAnchor = new GPoint(16, 0);
                        //var edificio = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/CabrioletRedblanco.png", null, "<%= ResolveUrl("~") %>Content/Images/CabrioletRedblancos.png");
                        var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/Flechas-180.gif", null, "<%= ResolveUrl("~") %>Content/Images/Flechas-180s.gif");
                        
                        //var center = new GLatLng(data[0], data[1]);
                        var center0=new GLatLng();
                        var pol = new Array();
                         $.each(response, function(i, data) {

                           //alert (center1);
                            var center = new GLatLng(data.Latitud, data.Longitud);
                            var center0=center;
                           
                            if(data.Grados==0)
                        {
                            sentido="N";

                            if (data.Velocidad>5)
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeN.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeNs.png");
                            }
                             else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaN.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaNs.png");
                            
                            }
                            else
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopN.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopNs.png");
                            }
                        }
                        
                        if ((data.Grados>0) && (data.Grados<90))
                        {
                            
                            sentido="NE";
                            
                            if (data.Velocidad>5)
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeNe.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeNes.png");
                            }
                             else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaNe.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaNes.png");
                            
                            }
                            else
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopNe.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopNes.png");
                            }

                        }
                        if(data.Grados==90)
                        {
                        
                        sentido="E";
                       
                        if (data.Velocidad>5)
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeE.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeEs.png");
                            }
                             else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaE.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaEs.png");
                            
                            }
                            else
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopE.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopEs.png");
                            }
                        
                        }
                        if((data.Grados>90) && (data.Grados<180))
                        {
                        
                         sentido="SE";   
                        
                          if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeSe.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeSes.png");
                         }
                          else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaSe.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaSes.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopSe.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopSes.png");
                          }  

                        }
                        if(data.Grados==180)
                        {
                        
                        sentido="S";
                        
                        if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeS.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeSs.png");
                        }
                         else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaS.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaSs.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopS.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopSs.png");
                          }
                        
                        }
                        if((data.Grados>180) && (data.Grados<270))
                        {
                        
                         sentido="SW";   
                         
                          if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeSw.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeSws.png");
                         }
                          else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaSw.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaSws.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopSw.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopSws.png");
                         }

                        }
                        if(data.Grados==270)
                        {
                        
                        sentido="W";
                        
                         if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeW.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeWs.png");
                        }
                         else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaW.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaWs.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopW.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopWs.png");
                            }
                        
                        }
                        if((data.Grados>270) && (data.Grados<360))
                        {
                        
                         sentido="NW";   
                         
                         if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeNW.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeNWs.png");
                         }
                          else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaNw.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaNw.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopNW.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopNWs.png");
                         }

                        }


                            map.setCenter(center, 10);
                            var marker = new GMarker(center,flecha);
                             map.addOverlay(marker);

                             var sentido;

                        

                             
                            marker.openInfoWindowHtml("<b style='color: #0000FF'>POSICION "+ i +"</b><br/><b>Alias: </b><i>" + data.NombreUnidad + "</i><br/><b>Placa: </b><i>" + data.PlacaUnidad + "</i><br/><b>Fecha/Hora: </b><i>" + data.Fecha + "</i><br/><b>Velocidad: </b><i>" + data.Velocidad   +" " +"Kph</i><br/><b>Sentido: </b><i>(" + data.Grados +")"+sentido+ "</i><br/><b>Evento: </b><i>" + data.EventoNombre + "</i>");
                            GEvent.addListener(marker, "click", function () {
                            marker.openInfoWindowHtml("<b style='color: #0000FF'>POSICION "+ i +"</b><br/><b>Alias: </b><i>" +data.NombreUnidad + "</i><br/><b>Placa: </b><i>" + data.PlacaUnidad + "</i><br/><b>Fecha/Hora: </b><i>" +data.Fecha + "</i><br/><b>Velocidad: </b><i>" + data.Velocidad +" " +"Kph</i><br/><b>Sentido: </b><i>(" + data.Grados +")"+ sentido+"</i><br/><b>Evento: </b><i>" + data.EventoNombre + "</i>");
                            });//fin funcion click
                          

                                

                                 pol[i]=center0;

                              

                         
                         });//fir iteracion

                         //alert("pol"+pol[5]);
                         var polyline = new GPolyline(pol, "#ff0000", 5); 
                         map.addOverlay(polyline);

                         map.setUIToDefault();
                         map.enableRotation();
                    }


                  


                //terminado success
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("error: "+XMLHttpRequest.responseText);
                }
            });
                
           

        }
    </script>
</asp:Content>
<asp:Content ID="Main" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
    <table>
    <tr>
    <td>
    
     <%if ((bool)ViewData["IsAdmin"])
          { %>
        Cliente:
        <%= Html.DropDownList("Clientes")%>
        <%} %>
        
        Unidad:
        <%: Html.DropDownList("comboUnidades")%>

    </td>
    
    <td>
       
        <label for="buscar">
            Fecha Desde:</label>
        <input type="text" name="fechaDesde" id="fechaDesde">
        <label for="buscar">
            Hora Desde:</label>
        <input type="text" id="tp" name="timepicker" />
        <%--<label for="buscar">Alias:</label>
     <%= Html.DropDownList("comboUnidades")%>	--%>
       
    </td>
    </tr>
    <tr>
    <td>
    </td>
    <td>
        <label for="buscar">
            Fecha Hasta :</label>
        <input type="text" name="fechaHasta" id="fechaHasta">
        <label for="buscar">
            Hora Hasta :</label>
        <input type="text" id="tp2" name="timepicker" />
        <input type="button" value="Aplicar" onclick="GetDatos();" />
        <input type="button" value="Aplicar Mapa" onclick="GetDatosMapa();" />
    </td>
    </tr>
    </table>
    <p align="center">
    </p>
    <p align="center">
    </p>
    <div id="map_canvas" style="width: 100%; height: 100%">
    </div>
</asp:Content>
